<?php
/**
 * 所有库存的分类值表
 * String attr_id
 * String attr_name
 * String attr_value
 */
class App_Model_StockAttr extends App_Model_Abstract
{
	public function init()
	{
		parent::init();
		$this->table = App_Db_Table::factory('StockAttr');
	}
	
	public function add($row)
	{
		return $this->table->insert($row);
	}
	
	public function listAll($row,$order,$page=1,$limit=20)
	{
		$select = $this->table->select();
		
		$select->where('isspecial = ?',$isspecial);
		if($ischeck!==false&&$ischeck!=""){
			$select->where('ischeck = ?',$ischeck);
		}
		if(!empty($starttime)){
			$select->where('addtime > ?',$starttime);
		}
		if(!empty($endtime)){
			$select->where('addtime < ?',$endtime);
		}
		$offset = ($page - 1) * $limit;
		$order = 'addtime';
		return $this->table->fetchAll($select,$order,$limit,$offset);
	}
	
	public function getAttrname($attr_name){
		$select = $this->table->select();
		$select->where('attr_name = ?',$attr_name);
		$select->group('attr_value');
		return $this->table->fetchAll($select);
	}
	public function getAttrvalue(){
		$select = $this->table->select();
		$order = '';
		return $this->table->fetchAll($select,$order);
	}
	
	public function getAttrByAttrid($attr_id){
		
		$db= $this->table->getAdapter();
		$where ="attr_id in ($attr_id)";
		$rows = $this->table->fetchAll($where);
		return $rows;
	}
	
	
	
	public function delete($sku)
	{
		$db = $this->table->getAdapter();
		$where = $db->quoteInto('sku = ?', $sku);
		
		$res = $this->table->delete($where);
		return $res;
	}

	
	public function getBySku($sku)
	{
		$db= $this->table->getAdapter();
		$where = $db->quoteInto('sku in (?)',$sku);
		$rows = $this->table->fetchAll($where);
		return $rows;
	}
	
}